﻿using LitJson;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace CL
{
    public class DataBase
    {
        public static void readData<T>(ref T data)
        {
            string path = getSavePath(data);
            //读取数据
            if (IOHelper.GetData(path) == null)
            {
                return;// data;
            }
            data = JsonMapper.ToObject<T>(IOHelper.GetData(path));
        }

        public static void saveData<T>(T data)
        {
            string path = getSavePath(data);
            //创建存档文件夹
            IOHelper.CreateDirectory(getSaveDir());
            //保存数据
            IOHelper.SetData(path, data);
        }

        /// <summary>
        /// 获得本地文件存储路径
        /// </summary>
        protected static string getSavePath<T>(T data)
        {
           // Debug.Log(getSaveDir() + data.ToString() + ".sav");
            return getSaveDir() + data.ToString() + ".sav";
        }

        protected static string getSaveDir()
        {
            return Application.persistentDataPath + "/Save";
        }
    }
}

